package com.bdqn.web.interceptor;

import com.bdqn.pojo.SysUser;
import com.bdqn.util.Constants;
import org.apache.log4j.Logger;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

//自定义拦截器
public class SysInterceptor extends HandlerInterceptorAdapter {
    private Logger logger = Logger.getLogger(HandlerInterceptorAdapter.class);

    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        logger.debug("拦截器执行了");
        HttpSession session = request.getSession();
        SysUser sysUser = (SysUser) session.getAttribute(Constants.USER_SESSION);
        if(null==sysUser){
            response.sendRedirect(request.getContextPath()+"/401.jsp");
            return false;
        }
        return true;
    }
}
